#!/bin/bash

echo "=========================="
echo "Starting..."
echo "=========================="

# Setting macros
delete_libs=1
compile_hdl=1
compile_e=0
run_modelsim=1
modelsim_gui=1

#deleting libraries
if [ $delete_libs -eq 1 ]; then
	echo "=========================="
	echo "Deleting libraries..."
	echo "=========================="

	rm -rf oa_v1_00_a
	rm -rf work
fi

# compiling HDL code
if [ $compile_hdl -eq 1 ]; then
	echo "=========================="
	echo "Compiling HDL modules/entities..."
	echo "=========================="

	# Compiling hdl code (command line mode with exit)
	#vsim -c -keepstdout -coverage -novopt -L SIMPRIMS_VER -L UNIMACRO_VER -L UNISIMS_VER -L XilinxCoreLib_ver -do system.do
	vsim -c -keepstdout -novopt -L SIMPRIMS_VER -L UNIMACRO_VER -L UNISIMS_VER -L XilinxCoreLib_ver -do system.do
fi

# compiling e code
if [ $compile_e -eq 1 ]; then
	echo "=========================="
	echo "Generating specman files..."
	echo "=========================="

	#generating specman files
	specman -c "load oa_test; write stubs -verilog"
	vlog -work work specman.v
fi

#running modelsim
if [ $run_modelsim -eq 1 ]; then
	echo "=========================="
	echo "Running ModelSim..."
	echo "=========================="

	if [ $modelsim_gui -eq 1 ]; then
		#specview vsim -keepstdout -coverage -pli $SPECMAN_HOME/linux/libmti_sn_boot.so -novopt -L SIMPRIMS_VER -L UNIMACRO_VER -L UNISIMS_VER -L XilinxCoreLib_ver -L work work.glbl -t ps specman system_tb -do wave.do
	    specview vsim -keepstdout -pli $SPECMAN_HOME/linux/libmti_sn_boot.so -novopt -L SIMPRIMS_VER -L UNIMACRO_VER -L UNISIMS_VER -L XilinxCoreLib_ver -L work work.glbl -t ps specman system_tb -do wave_stress.do -wlf my_stress.wlf
	else
		specrun vsim -c -keepstdout -coverage -pli $SPECMAN_HOME/linux/libmti_sn_boot.so -novopt -L SIMPRIMS_VER -L UNIMACRO_VER -L UNISIMS_VER -L XilinxCoreLib_ver -L work work.glbl -t ps specman system_tb -do wave_myarctan.do
	fi
fi
